﻿Imports GMap.NET
Imports GMap.NET.WindowsForms

Public Class CarMarker1
    Inherits GMapMarker

    Protected _MarkerImage As Image = My.Resources.Resources.bmw_mini_icon_32

    Protected _Text As String = ""
    Protected Font As New Font("Arial", 10, FontStyle.Regular)

    Public Property Image() As Image
        Get
            Return _MarkerImage
        End Get
        Set(ByVal value As Image)
            _MarkerImage = value
        End Set
    End Property

    Public Property Text As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property

    Public Bearing As System.Nullable(Of Single)

    Public Sub New(ByVal p As PointLatLng)
        MyBase.New(p)
        ' This call is required by the designer.
        'InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        Size = New System.Drawing.Size(_MarkerImage.Width, _MarkerImage.Height)


    End Sub

    Public Overrides Sub OnRender(ByVal g As Graphics)
        If _MarkerImage IsNot Nothing Then
            g.DrawImage(_MarkerImage, Me.LocalPosition)
        End If

        'Make some adjustments to the position here depending on your image
        CenterTextAt(g, _Text, Me.LocalPosition.X + 20, Me.LocalPosition.Y + _MarkerImage.Height)
        'CenterTextAt(g, _Text, Me.LocalPosition.X + _MarkerImage.Width, Me.LocalPosition.Y + _MarkerImage.Height)
        'CenterTextAt(g, _Text, Me.LocalPosition.X, Me.LocalPosition.Y)
    End Sub

    Public Sub CenterTextAt(ByVal gr As Graphics, ByVal txt As String, ByVal x As Single, ByVal y As Single)

        ' Make a StringFormat object that centers.
        Dim sf As New StringFormat
        sf.LineAlignment = StringAlignment.Center
        sf.Alignment = StringAlignment.Center

        ' Draw the text.
        gr.DrawString(txt, Font, Brushes.Black, x, y, sf)
        sf.Dispose()
    End Sub

End Class



